package com;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class SocktAction extends Action {

	/**
	 * 测试返回xml
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String str = getXml();
		 response.setContentType("text/xml");
         response.setCharacterEncoding("utf-8");
         response.setHeader("Cache-Control", "no-cache");
         PrintWriter out = response.getWriter();
         out.println(str);
         System.out.println(str);
         out.flush();
         out.close();
		return null;
	}
	/**
	 * 封装xml
	 * @return
	 */
	public String getXml(){
		StringBuffer sb = new StringBuffer();
		sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		  sb.append("<root>");//
		  	sb.append("<infos>");//
		  	for(int i=0;i<10;i++){
		  			sb.append("<info id='"+i+"'>");//
						sb.append("<datasn>"+i+"</datasn>");//<!-- 受助者编号 如531000000100203100-->
		  				sb.append("<name>name "+i+"</name>");//<!-- 受助者姓名-->
		  				sb.append("<sex>sex</sex>");//<!-- 性别 1 男，0 女-->
		  				sb.append("<birthday>1998-2-9</birthday>");//<!-- 出生年月 yyyy-MM-dd-->
		  				sb.append("<projectname>受助项目"+i+"</projectname>");//<!--受助项目名称-->
		  				sb.append("<prov>省市"+i+"</prov>");//<!--所在省市名称-->
		  				sb.append("<startingdate>开机日期"+i+"</startingdate>");//<!--开机日期 yyyy-MM-dd -->
		  				sb.append("<surgeryage>手术年龄"+i+"</surgeryage>");//<!--手术年龄 int型 -->
		  				sb.append("<surgerydate>手术日期"+i+"</surgerydate>");//<!--手术日期 yyyy-MM-dd -->
		  				sb.append("<declareage>申报年龄"+i+"</declareage>");//<!--申报年龄 int型 -->
					sb.append("</info>");//
			}
//		  			.....
			sb.append("</infos>");
		  sb.append("</root>");
		
		return sb.toString();
	}

}
